<template>
  <div>
    <HomeHeader></HomeHeader>
    <HomeSwiper :swiper="swiper"></HomeSwiper>
    <HomeIcons :icons="icons"></HomeIcons>
    <HomeRecommend :recommend="recommend"></HomeRecommend>
    <HomeWeekend :weekend="weekend"></HomeWeekend>
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axious from 'axios'
import { mapState } from 'vuex'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  data () {
    return {
      swiper: [],
      icons: [],
      recommend: [],
      weekend: [],
      beforeCity: ''
    }
  },
  methods: {
    getHomeInfoSucc (res) {
      this.swiper = res.data.data.swiperList
      this.icons = res.data.data.iconList
      this.recommend = res.data.data.recommendList
      this.weekend = res.data.data.weekendList
    },
    getHomeInfo () {
      axious.get('/api/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    }
  },
  mounted () {
    this.getHomeInfo()
    this.beforeCity = this.city
  },
  computed: {
    ...mapState(['city'])
  },
  activated () {
    if (this.city !== this.beforeCity) {
      this.getHomeInfo()
      this.beforeCity = this.city
    } else {
      console.log('相同城市不再发送请求')
    }
  }
}
</script>

<style scoped>

</style>
